// pages/control/component/summaryDate/summaryData.js

/**
 * @file 展示总结的数据（根据item_layout可选三种模式）
 * @example 见production_uchart.js;
 * 
 * html
 * <summaryData summary="{{summary}}" item_layout="vertical"></summaryData>
 * 
 * js
 * data:{
 *   summary:[{  
 *    title:"日",
 *    info:"111"
 *  },{
 *    title:"月",
 *    info:"111"
 *  },{
 *    title:"年",
 *    info:"111"
 *  },],
 * }
 * 
 * json
 * 略
 */

const util=require("../../../../utils/util")

Component({  
  /**  
   * 组件的属性列表  
   */  
  properties: {  
    summary: {  
      type: Object,  
      value: {}, 
    },  
    item_layout: {  
      type: String,  
      value: 'vertical',  
    },  
  },  
  
  /**  
   * 组件的初始数据  
   */  
  data: {},  
  
  lifetimes: {  
    attached() {  
      this.dealProperties();  
    },  
  },  
  
  /**  
   * 组件的方法列表  
   */  
  methods: {  
    dealProperties() {  
      // 根据item_layout来设定summary的长度  
      const maxSummaryLength = {  
        vertical: 5,  
        horizontal: 3,  
        'vertical-reverse': 5,  
      }[this.data.item_layout] || maxSummaryLength.vertical;
        
      if (!util.isEmptyObject(this.data.summary) && this.data.summary.length > maxSummaryLength) {  
        this.setData({  
          summary: this.data.summary.slice(0, maxSummaryLength),  
        });  
      } else if (util.isEmptyObject(this.data.summary)) {  
        // 对空对象的处理，例如设置为默认值或者抛出警告等，根据你的需求来决定  
        console.warn('Empty summary object!');  
      }  
    },  
  },  
});